<!DOCTYPE HTML>
<html class="bg-eee">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>添加商品</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mobiscroll_002.css" >
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>

    <script src="../script/mobiscroll_002.js" type="text/javascript"></script>
    <script src="../script/mobiscroll_004.js" type="text/javascript"></script>
    <script src="../script/mobiscroll.js" type="text/javascript"></script>
    <script src="../script/mobiscroll_003.js" type="text/javascript"></script>
    <script src="../script/mobiscroll_005.js" type="text/javascript"></script>

</head>
<body class="bg-eee">
    <header class="header">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="pageTitle">修改商品</div>
    </header>
    <section class="memberInfoPage bg-fff HTML_BOX">
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <ul class="settings wareAddPage plr bg-fff">
            <!--<li class="displayFlex">
                <span>商品分类</span>
                <select class="wareType">
                    <option selected="selected">水果</option>
                    <option>饮料</option>
                    <option>零食</option>
                    <option>蔬菜</option>
                    <option>肉类</option>
                </select>
            </li> -->
            <li class="displayFlex left_input">
                <span>商品名称</span>
                <div class="inputInfo"><input placeholder="请输入名称" tyoe="text" /></div>
            </li>
            <li class="displayFlex left_input">
                <span>英文名称</span>
                <div class="inputInfo"><input placeholder="请输入英文名称" tyoe="text" /></div>
            </li>
            <li class="displayFlex left_input">
                <span>商品原价</span>
                <div class="inputInfo"><input type="number" placeholder="请输入原格" /></div>
            </li>
            <li class="displayFlex left_input">
                <span>商品现价</span>
                <div class="inputInfo"><input type="number" placeholder="请输入现格" /></div>
            </li>
            <li class="displayFlex left_input">
                <span>库存数量</span>
                <div class="inputInfo"><input placeholder="请输入数量" tyoe="number" /></div>
            </li>
            <li class="displayFlex left_input">
                <span>今天特卖</span>
                <select id="flags" class="wareType">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </li>
        </ul>
        <ul class="wareAddPageBox1 plr bg-fff">
            <li class="">
                <div class="pageItem">
                    <span class="mr10">开始时间：</span>
                    <input placeholder="促销开始时间" tyoe="text" />
                </div>
                <div class="pageItem">
                    <span class="mr10">结束时间：</span>
                    <input placeholder="促销结束时间" tyoe="text" />
                </div>
            </li>
            <!-- <li class="">
                <div class="pageItem">
                    <span>重量：</span>
                    <input placeholder="" tyoe="text" />
                </div>
                <div class="pageItem">
                    <span>运费：</span>
                    <input placeholder="" tyoe="text" />
                </div>
            </li> -->
        </ul>
        <!-- <div class="wareAddPageTitle plr">商品主图</div>
        <div class="addImageBox">
            <div class="imgItem">
                <img src="../image/ware_1.png" />
            </div>
            <div class="addWareImg">
                <img src="../image/addImg_icon.png"/>
            </div>
        </div> -->
        <!-- <div class="wareAddPageTitle plr">商品详情</div>
        <div class="liuyanBox">
            <div class="liuyanItem">
                <textarea autoHeight="true" placeholder="请输入详细描述" class="liuyanarea"></textarea>
            </div>
        </div> -->
        <div style="height: 1rem;width: 100%"></div>

    </section>
    <section class="footer wareAddFooter f_c">确认修改</section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript"> 
	var param = {};
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        param = api.pageParam;
        ifCnAndEn();
        ready();
    };

    function ready(){
        pop.loading();
        getAjax(Interface.merchant_goods_info,{token:token,id:param.id},function(res){
            pop.close();
            console.log(JSON.stringify(res));
            var data = res.data;
            $(".wareAddPage li").eq(0).find("input").val(data.title);
            $(".wareAddPage li").eq(1).find("input").val(data.egname);
            $(".wareAddPage li").eq(2).find("input").val(data.old_price);
            $(".wareAddPage li").eq(3).find("input").val(data.new_price);
            $(".wareAddPage li").eq(4).find("input").val(data.stock);
            $(".wareAddPageBox1 li").find("input").eq(0).val(timestampToTime2(data.cuxiao_start));
            $(".wareAddPageBox1 li").find("input").eq(1).val(timestampToTime2(data.cuxiao_end));
            if(data.flags == 0){
                $("#flags option[val='0']").attr("selected", true); 
            }else{
                $("#flags option[val='1']").attr("selected", true);
            }
            param.have_goods = data.have_goods;
        },function(res,err){})
    }

    $(".wareAddFooter").click(function(){
        var layers = "";
        var isnull = false;
        $(".settings input").each(function(i,item){
            var val = $(item).val();
            if(val == "" && !isnull){
                switch(i){
                    case 0:
                    layers = "请输入中文名称";
                    isnull = true;
                    break;
                    case 1:
                    layers = "请输入英文名称";
                    isnull = true;
                    break;  
                    case 2:
                    layers = "请输入原价";
                    isnull = true;
                    break; 
                    case 3:
                    layers = "请输入现价";
                    isnull = true;
                    break; 
                    case 4:
                    layers = "请输入库存";
                    isnull = true;
                    break; 
                }
            }
        });
        // $(".wareAddPageBox1 input").each(function(i,item){
        //     var val = $(item).val();
        //     if(val == "" && !isnull){
        //         switch(i){
        //             case 0:
        //             layers = "请输入促销开始时间";
        //             isnull = true;
        //             break;
        //             case 1:
        //             layers = "请输入促销结束时间";
        //             isnull = true;
        //             break;  
        //         }
        //     }
        // });
        if(isnull){
            console.log(layers);
            pop.notice(layers);
            return;
        }
        var p = {
            token:token,
            id: param.id,
            title:$(".wareAddPage li").eq(0).find("input").val(),
            egname:$(".wareAddPage li").eq(1).find("input").val(),
            old_price:$(".wareAddPage li").eq(2).find("input").val(),
            price:$(".wareAddPage li").eq(3).find("input").val(),
            stock:$(".wareAddPage li").eq(4).find("input").val(),
            cuxiao_start:$(".wareAddPageBox1 li").find("input").eq(0).val(),
            cuxiao_end:$(".wareAddPageBox1 li").find("input").eq(1).val(),
            flags:$("#flags").val(),
            have_goods:param.have_goods,
        }
        getAjax(Interface.merchant_edit_goods,p,function(res){
            console.log(JSON.stringify(res));
            api.sendEvent({
                name: 'wareAdd',
                extra: {}
            });
            pop.notice(res.msg,1,function(){
                historyBack();
            });
        },function(res,err){})
    });
    //时间选择
    var currYear = '1800';
    var opt={};
    var l='zh';
    if(cnen ==2){
        l='en';
    }
    var today = "重置";
    if(cnen ==2){
        today='Today';
    }
    opt.date = {preset : 'date'};
    opt.datetime = {preset : 'datetime'};
    opt.time = {preset : 'time'};
    opt.default = {
        theme: 'android-ics light', //皮肤样式
        display: 'modal', //显示方式
        mode: 'scroller', //日期选择模式
        dateFormat: 'yyyy-mm-dd',
        lang: l,
        showNow: true,
        nowText: today,
        //minDate: new Date(),  //无法选择以前的时间
        endYear:Number(new Date().getFullYear())+100,
        startYear: currYear, //开始年份
    };
    var optDateTime = $.extend(opt['date'], opt['default']);
    $(".wareAddPageBox1 li").find("input").eq(0).mobiscroll(optDateTime);
    $(".wareAddPageBox1 li").find("input").eq(1).mobiscroll(optDateTime);
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".pageTitle").eq(0).html('Modify Ware');     
            $(".wareAddPage li").eq(0).find("input").attr("placeholder",'');
            $(".wareAddPage li").eq(1).find("input").attr("placeholder",'');
            $(".wareAddPage li").eq(2).find("input").attr("placeholder",'');
            $(".wareAddPage li").eq(3).find("input").attr("placeholder",'');
            $(".wareAddPage li").eq(4).find("input").attr("placeholder",'');
            $(".wareAddPageBox1 li").find("input").eq(0).attr("placeholder",'');
            $(".wareAddPageBox1 li").find("input").eq(1).attr("placeholder",'');
            $(".wareAddPage li").eq(0).find("span").html('Name');
            $(".wareAddPage li").eq(1).find("span").html('English name');
            $(".wareAddPage li").eq(2).find("span").html('Old price');
            $(".wareAddPage li").eq(3).find("span").html('New price');
            $(".wareAddPage li").eq(4).find("span").html('Stock');
            $(".wareAddPage li").eq(5).find("span").html('Special sale');
            $("#flags").html('<option value="1">Yes</option><option value="0">No</option>')
            $(".wareAddPageBox1 li").find("span").eq(0).html('Start time');
            $(".wareAddPageBox1 li").find("span").eq(1).html('End time');
            $(".wareAddFooter").html("Modify");
        }
    }
</script>
</html>